package com.example.wacoffee_manage.Mapper;

import com.example.wacoffee_manage.pojo.Good;
import com.example.wacoffee_manage.pojo.Supply;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SupplyMapper {

    List<Supply> getAll(Supply supply);

    List<Good> getProductsBySupplyId(Integer id);

    @Update("UPDATE good g left join good_supply gs on gs.good_id=g.id SET stock = stock + #{stock} WHERE gs.supply_id=#{id} and gs.good_id=#{productId} ")
    void addStock(Integer id, Integer productId, Integer stock);

    @Select("select id,name from supply where id=#{id}")
    Supply getSupplyById(Integer id);


    @Update("update supply set name=#{name} where id=#{id}")
    void update(Supply supply);

    @Update("delete from supply where id=#{id}")
    void delete(Integer id);

   @Select("select count(*) from good_supply where supply_id=#{id}")
    int judgeSupplyAppearGood(Integer id);
}
